/**
 * OschinaApp For React-Native
 */

'use strict';

import * as React from 'react-native';
import * as Color from './app/node_modules/values/color';
import Router from './app/node_modules/views/Router';
import Application from './app/node_modules/public/Application';

let {
    AppRegistry,
    View,
    BackAndroid,
    StatusBar,
    Navigator
} = React;

BackAndroid.addEventListener('hardwareBackPress', function() {
    let nav = Application.Navigation;
    if (nav && nav.getCurrentRoutes().length > 1) {
        nav.pop();
        return true;
    }
    return false;
});
let app = React.createClass({
    render () {
        return (
            <View style={{flex: 1}}>
                <StatusBar
                    backgroundColor={Color.darkPrimaryColor}
                    barStyle="light-content"/>
                <Navigator
                    initialRoute={{id: 'SplashScene', name: '启动页', index: 0}}
                    configureScene={(route, routeStack) => Navigator.SceneConfigs.HorizontalSwipeJumpFromRight}
                    renderScene={this.renderMapper}/>
            </View>
        )
    },
    renderMapper (router, navigator) {
        Application.Navigation = navigator;
        return Router(router, navigator)
    }
});

AppRegistry.registerComponent('OschinaAppForReactNative', () => app);
